<template>
  <div class="warehouse">
    <div style="display: flex; justify-content: flex-end">
      <!--      <div>
        <el-button size="medium" type="primary" plain @click="caigoAdd">
			产品入库
		</el-button>
      </div> -->
      <div style="display: flex">
        <el-select v-model="receiptsStatusValue" style="width: 150px" placeholder="入库状态" @change="getAllGoods">
          <el-option label="全部" :value="null"></el-option>
          <el-option label="已通过" :value="0"></el-option>
          <el-option label="待审核" :value="1"></el-option>
          <el-option label="不通过" :value="2"></el-option>
        </el-select>
        <el-button @click="reset" style="margin-left: 10px;" v-debounce>
          重置
        </el-button>
      </div>
    </div>

    <div class="goods-table">
      <el-table :data="tableData" v-loading="loading" border stripe style="width: 100%" height="100%">
        <el-table-column prop="i" fixed="left" label="序号" width="50">
        </el-table-column>
        <el-table-column prop="suppliersName" label="供应商名称" width="200">
        </el-table-column>
        <el-table-column label="零件列表" width="80">
          <template slot-scope="scope">
            <el-button type="text" @click="partsOpen(scope.row)">点击查看</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="userName" label="采购人" width="80">
        </el-table-column>
        <el-table-column prop="price" label="总金额" width="80">
        </el-table-column>
        <el-table-column prop="paymentMethod" label="结款方式" width="80">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.paymentMethod === 0" effect="dark">现金</el-tag>
            <el-tag v-if="scope.row.paymentMethod === 1" effect="dark" type="warning">
              月结
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="receiptsTime" label="入库时间" width="100">
        </el-table-column>
        <el-table-column prop="nickName" label="申请人" width="80">
        </el-table-column>
        <el-table-column prop="managementName" label="审核人" width="80">
        </el-table-column>
        <el-table-column prop="applyTime" label="审核时间" fit>
        </el-table-column>
        <el-table-column label="操作" width="220" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" :type="applyType(scope.row.receiptsStatus)"
              :disabled="applyDisabled(scope.row.receiptsStatus)" @click="applyShow(scope.row, 0)">
              {{ applyButtonText(scope.row.receiptsStatus) }}
            </el-button>
            <el-button size="mini" type="primary" @click="applyShow(scope.row, 1)">
              详情
            </el-button>
            <el-button size="mini" type="danger" @click="deleteOrder(scope.row)" v-if="userInfo.roleId === '1'">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="currentPage" :page-sizes="[20, 50, 100]" :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>

    <!-- 查看零件列表弹窗 -->
    <el-dialog style="margin-top:0" :visible.sync="partsShow" width="85%" :title="selectTitle" @close="partsClose">
      <div class="data-table">
        <el-table :data="selectPurchase.parts" border style="width: 100%" :max-height="500" :row-style="tableRow">
          <el-table-column prop="i" fixed="left" label="序号" width="60">
          </el-table-column>
          <el-table-column label="图片" width="120">
            <template slot-scope="scope">
              <el-image :src="READ_IMG_URL + scope.row.image" style="width: 90px; height: 90px;"
                :preview-src-list="new Array(READ_IMG_URL + scope.row.image)">
              </el-image>
            </template>
          </el-table-column>
          <el-table-column prop="partName" label="零件名称" fit>
          </el-table-column>
          <el-table-column prop="model" label="零件型号" fit>
          </el-table-column>
          <el-table-column prop="devicesDescribe" label="产品描述" fit>
          </el-table-column>
          <el-table-column prop="remark" label="备注" fit>
          </el-table-column>
          <el-table-column prop="purchasePrice" label="采购单价" width="120">
          </el-table-column>
          <el-table-column prop="cost" label="上次单价" width="80">
            <template slot-scope="scope">
              <span v-if="scope.row.cost < scope.row.purchasePrice" style="color: red;">
                {{ scope.row.cost }}
              </span>
              <span v-else-if="scope.row.cost > scope.row.purchasePrice" style="color: lawngreen;">
                {{ scope.row.cost }}
              </span>
              <span v-else>{{ scope.row.cost }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="freight" label="运输费" width="100">
          </el-table-column>
          <el-table-column prop="isIncludeTax" label="是否含税" width="120">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.isIncludeTax === 0">含税</el-tag>
              <el-tag v-if="scope.row.isIncludeTax === 1" type="danger">
                不含税
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="partCount" label="采购数量" width="120">
          </el-table-column>
          <el-table-column prop="totalPrice" label="总计" width="120">
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
    <!-- 审核弹窗 -->
    <el-dialog style="margin-top: 0" width="75%" :visible.sync="applyDialog" :title="applyTitle">
      <el-form inline label-position="top" :model="selectPurchase">
        <el-form-item label="订单编号" style="width: 450px;">
          <el-input v-model="selectPurchase.id" placeholder="订单编号" readonly>
          </el-input>
        </el-form-item>
        <el-form-item label="供应商" style="width: 450px;">
          <el-input :value="selectPurchase.suppliersName" readonly>
          </el-input>
        </el-form-item>
        <el-form-item label="采购人" style="width: 450px;">
          <el-input :value="selectPurchase.userName" readonly>
          </el-input>
        </el-form-item>
        <el-form-item label="结款方式" style="width: 450px;">
          <el-select v-model="selectPurchase.paymentMethod" disabled style="width: 100%;">
            <el-option label="现金" :value="0"></el-option>
            <el-option label="月结" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="总金额" style="width: 450px;">
          <el-input v-model="selectPurchase.price" type="number" placeholder="总金额" step="0.01" readonly>
          </el-input>
        </el-form-item>
        <el-form-item label="采购备注" style="width: 450px;">
          <el-input v-model="selectPurchase.remark" placeholder="备注" readonly>
          </el-input>
        </el-form-item>
        <el-form-item label="零件列表" style="width: 100%;">
          <div>
            <el-table :data="selectPurchase.parts" border style="width: 100%" :max-height="400" :row-style="tableRow">
              <el-table-column prop="i" fixed="left" label="序号" width="60">
              </el-table-column>
              <el-table-column label="图片" width="120">
                <template slot-scope="scope">
                  <el-image :src="READ_IMG_URL + scope.row.image" style="width: 90px; height: 90px;"
                    :preview-src-list="new Array(READ_IMG_URL + scope.row.image)">
                  </el-image>
                </template>
              </el-table-column>
              <el-table-column prop="partName" label="零件名称" fit>
              </el-table-column>
              <el-table-column prop="model" label="零件型号" fit>
              </el-table-column>
              <el-table-column prop="purchasePrice" label="采购单价" width="100">
              </el-table-column>
              <el-table-column prop="cost" label="上次单价" width="80">
                <template slot-scope="scope">
                  <span v-if="scope.row.cost < scope.row.purchasePrice" style="color: red;">
                    {{ scope.row.cost }}
                  </span>
                  <span v-else-if="scope.row.cost > scope.row.purchasePrice" style="color: lawngreen;">
                    {{ scope.row.cost }}
                  </span>
                  <span v-else>{{ scope.row.cost }}</span>
                </template>
              </el-table-column>
              <el-table-column prop="freight" label="运输费" width="100">
              </el-table-column>
              <el-table-column prop="isIncludeTax" label="是否含税" width="100">
                <template slot-scope="scope">
                  <el-tag v-if="scope.row.isIncludeTax === 0">含税</el-tag>
                  <el-tag v-if="scope.row.isIncludeTax === 1" type="danger">
                    不含税
                  </el-tag>
                </template>
              </el-table-column>
              <el-table-column prop="partCount" label="采购数量" width="100">
              </el-table-column>
              <el-table-column prop="totalPrice" label="总计" width="100">
              </el-table-column>
            </el-table>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="applyButton">
        <el-button type="danger" @click="applyOrders(2)" v-debounce>驳回</el-button>
        <el-button type="success" @click="applyOrders(0)" v-debounce>通过</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import dayjs from "dayjs";
import {
  selectEmployeeProfileByAdmin,
  // getGoodsCategory,
  addEmployeeProfile,
  deleteEmployeeProfileById,
  selectEmployeeProfileById,
  UploadFile,
  updateEmployeeProfile,
  updateEmployeeUpdateStatus,
  selectEmployeeProfileByName,
  apply, //新增产品
  suppliersList, //供应商列表
  suppliersAdd, //新增供应商
  purchaseList, //采购订单列表
  selectName, //查询产品名称
  purchaseReceiptsApply, //申请入库
  purchaseInfoList, //采购订单列表
  adminCheck, //审核入库
  purchaseReceiptsInfo, //通过id查询入库信息
  purchaseReceiptsInfoList, //查询入库信息
  purchaseReceiptsInfos, //模糊查询入库信息
  updateReceiptsInfo, //修改入库信息
} from "../../api/all";
import warehouseApi from "../../api/warehouse";
import config from '../../api/apiURL.js';
export default {
  components: {},
  data() {
    return {
      READ_IMG_URL: config.READ_IMG_URL,
      userInfo: {},
      role1: false,
      root: false,
      cgst: 0,
      //临时采购订单号
      ItPurchaseOrdersId: "",
      receiptsStatusValue: null,
      receiptsStatusList: [
        { value: "-1", label: "全部" },
        { value: "0", label: "已入库" },
        { value: "1", label: "待审核" },
        { value: "2", label: "入库失败" },
        { value: "3", label: "待财务审核" },
      ],
      //采购订单列表
      options3: [
        { value: "选项1", label: "黄金糕" },
        { value: "选项2", label: "双皮奶" },
        { value: "选项3", label: "蚵仔煎" },
        { value: "选项4", label: "龙须面" },
        { value: "选项5", label: "北京烤鸭" },
      ],
      value3: "",
      //供应商列表
      options2: [
        { partName: "小马", model: "Y780" },
        { partName: "中马", model: "Y880" },
        { partName: "大马", model: "Y980" },
      ],
      loading2: false,
      value2: "",
      suppliers: {
        suppliersId: "", //供应商id
        suppliersName: "", //供应商名称
        suppliersAddress: "", //供应商地址
        suppliersPhone: "", //供应商电话
      },
      //搜索框的值
      input: "",
      // 图片预览
      srcList: [],
      srcList2: [],
      // 上传图片文件
      selectedFile: null,
      //判断用户点击的是合同还是保密协议
      htdz: "",
      //新增产品按钮状态
      bt1: false,
      bt2: false,
      role3: false,
      // 合同地址
      imageUrl: "",
      // 保密协议地址
      imageUrl2: "",
      //新增标题
      title: "新增产品",
      roleType: false,
      cover: "cover",
      // 显示表单
      addFromDialog: false,
      addFromDialog2: false,
      addFromDialog3: false,
      addFromDialog4: false,
      addFromDialog6: false,

      // 表格加载
      loading: false,
      //合同到期提醒
      dialogImageUrl: "",
      dialogVisible: false,
      //新增采购表格数据
      prudproducts: {
        suppliersId: "", //供应商id
        productsId: "", //产品id
        productsName: "", //产品名称
        description: "", //产品描述
        price: "", //产品价格
        model: "", //产品型号
        isIncludingTax: "", //是否含税
        number: "", //产品数量
        image: "", //产品图片
        purchaser: "", //采购人
        storageTime: "", //入库时间
        paymentType: "", //结款方式 (1现金,2月结)
        status: "", //入库状态 （0已通过，1待审核,2审核失败）
      },
      //采购入库信息
      PurchaseReceipts: {
        productsName: "", //产品名称
        purchaseOrdersId: "", //采购订单ID
        model: "", //产品型号
        price: "", //产品价格
        number: "", //产品数量
        isIncludingTax: "", //是否含税
        storageTime: "", //入库时间
        description: "", //产品描述
        image: "", //产品图片
        receiptsId: "", //入库id
        warehouseDevId: "", //仓库id
      },
      //表格数据
      tableData: [],
      // 新增员工档案信息
      addEmployeeForm: {
        id: "",
        userId: "",
        employeeName: "",
        employeeSex: 0,
        employeeBirthday: null,
        employeeAge: 0,
        employeeIdcard: "",
        employeeEmail: "",
        employeeEntryDate: "",
        employeeLeaveDate: "",
        employeeContractDate: "",
        employeeContractFile: "",
        employeeSecrecyFile: "",
        employeeStatus: 0,
        employeeUpdateStatus: 0,
        employeeUpdateCount: 0,
        createTime: "",
        updateTime: "",
      },
      //总数页
      total: 1,
      // 分页大小
      pageSize: 50,
      //记录当前页数
      currentPage: 1,
      //审核通过状态
      applyStatus: false,
      //是否含税
      SexCategory: [
        { label: "是", value: 0 },
        { label: "否", value: 1 },
      ],
      SexCategory2: [
        { label: "现金全款", value: 0 },
        { label: "分期付款 3期", value: 3 },
        { label: "分期付款 6期", value: 6 },
        { label: "分期付款 9期", value: 9 },
        { label: "分期付款 12期", value: 12 },
      ],
      SexCategory3: [],
      SexCategory4: [
        { label: "成品", value: 0 },
        { label: "零件", value: 1 },
      ],
      //在职信息
      employeeStatusCategory: [
        { label: "在职", value: 0 },
        { label: "离职", value: 1 },
      ],
      selectPurchase: {},
      applyButton: true,
      partsShow: false,
      selectTitle: "",
      applyTitle: "",
      applyDialog: false
    };
  },
  mounted() {
    this.userInfo = JSON.parse(localStorage.getItem("userInfo"));
    if (this.userInfo.roleId == 1) {
      this.root = true;
      this.roleType = true;
    }
    this.getAllGoods();
  },
  //超级管理员显示功能
  methods: {
    // 格式化时间
    formatDate(date) {
      const d = new Date(date);
      const year = d.getFullYear();
      const month = (d.getMonth() + 1).toString().padStart(2, "0");
      const day = d.getDate().toString().padStart(2, "0");
      const hours = d.getHours().toString().padStart(2, "0");
      const minutes = d.getMinutes().toString().padStart(2, "0");
      const seconds = d.getSeconds().toString().padStart(2, "0");
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;

      // return `${year}-${month}-${day}`;
    },
    startTimeChange(value) {
      this.addEmployeeForm.startTime = dayjs(value).format(
        "YYYY-MM-DD HH:mm:ss"
      );
      console.log("上架时间", dayjs(value).format("YYYY-MM-DD HH:mm:ss"));
    },
    endTimeChange(value) {
      this.addEmployeeForm.endTime = dayjs(value).format("YYYY-MM-DD HH:mm:ss");
      console.log("上架时间", dayjs(value).format("YYYY-MM-DD HH:mm:ss"));
    },
    //新增供应商
    addSupplierInfo() {
      suppliersAdd(this.suppliers).then((data) => {
        console.log("data", data.data);
        if (data.code == 200) {
          this.$message({
            type: "success",
            message: data.message,
          });
          this.addFromDialog3 = false;
          //再次查询供应商列表
          suppliersList().then((data) => {
            this.SexCategory3 = data.data;
          });
        } else {
          this.$message({
            type: "error",
            message: data.message,
          });
        }
      });
    },
    //入库状态方法
    receiptsStatus(i) {
      let val = "";
      if (i == 0) {
        val = "已入库";
      } else if (i == 1) {
        val = "待审核";
      } else if (i == 2) {
        val = "入库失败";
      } else if (i == 3) {
        val = "待财务审核";
      }
      return val;
    },
    // 新增产品
    submitaddEmployeeForm() {
      let val = this.infoPet();
      if (val == false) {
        return;
      }
      addEmployeeProfile(this.addEmployeeForm).then((data) => {
        if (data.code) {
          this.$message({
            type: "success",
            message: "新增成功",
          });
          this.getAllGoods();
        } else {
          this.$message({
            type: "error",
            message: "新增失败",
          });
        }
      });
      this.addFromDialog = false;
    },
    //updateReceiptsInfo
    updateRecItnfo() {
      updateReceiptsInfo(this.PurchaseReceipts).then((data) => {
        if (data.code == 200) {
          this.$message({
            type: "success",
            message: "修改成功",
          });
          this.getAllGoods();
        } else {
          this.$message({
            type: "error",
            message: "修改失败",
          });
        }
      });
    },
    //校验新增修改申请时的数据
    infoPet() {
      this.prudproducts.status = 1;
      //校验入库表格不能为空
      if (false) {
        console.log(this.prudproducts);
        this.$message({
          type: "error",
          message: "请填写完整信息",
        });
      } else {
        //添加入库申请
        apply(this.prudproducts).then((data) => {
          if (data.code) {
            this.$message({
              type: "success",
              message: "入库申请成功",
            });
            this.getAllGoods();
          } else {
            this.$message({
              type: "error",
              message: "入库申请失败",
            });
          }
        });
        return true;
      }
    },
    //修改档案信息
    UpdateEmployee(i) {
      if (i == 2) {
        this.infoPet();
        return;
      }
      if (i == 3) {
        //申请入库
        this.PurchaseReceipts.purchaseOrdersId = this.value3;
        purchaseReceiptsApply(this.PurchaseReceipts).then((data) => {
          if (data.code == 200) {
            this.$message({
              type: "success",
              message: data.message,
            });
            this.getAllGoods();
          } else {
            this.$message({
              type: "error",
              message: data.message,
            });
          }
        });
        return;
      }
      updateEmployeeProfile(this.addEmployeeForm).then((data) => {
        if (data.code) {
          this.$message({
            type: "success",
            message: data.data,
          });
          this.getAllGoods();
          this.addFromDialog = false;
        } else {
          this.$message({
            type: "error",
            message: data.message,
          });
        }
      });
    },
    receiptsStatusSelect() {
      console.log(this.receiptsStatusValue);
      purchaseReceiptsInfoList(
        this.currentPage,
        this.pageSize,
        this.receiptsStatusValue
      ).then((data) => {
        this.total = data.data.total;
        this.tableData = data.data.purchaseInfoVoList.map((item, index) => {
          item.i = (this.currentPage - 1) * this.pageSize + index + 1;
          return item;
        });
      });
    },
    //输入框值发生变化
    inputName() {
      selectName(this.PurchaseReceipts.productsName).then((data) => {
        this.options2 = data.data;
        if (data.data.length == 0) {
          this.loading2 = false;
        } else {
          this.loading2 = true;
        }
      });

      console.log("获得焦点");
    },
    //失去焦点
    // blur() {
    //   this.loading2 = false;
    //   console.log(this.options2);
    // },
    setName(i) {
      this.PurchaseReceipts.productsName = this.options2[i].partName;
      this.PurchaseReceipts.model = this.options2[i].model;
      this.PurchaseReceipts.number = this.options2[i].count;
      this.PurchaseReceipts.price = this.options2[i].price;
      this.PurchaseReceipts.description = this.options2[i].remark;
      this.PurchaseReceipts.isIncludeTax = this.options2[i].isIncludeTax;
      this.PurchaseReceipts.image = this.options2[i].image;
      this.PurchaseReceipts.isProduct = this.options2[i].isProduct;
      this.PurchaseReceipts.warehouseDevId = this.options2[i].id;

      this.loading2 = false;
    },
    //模糊查询信息
    likeEmployee() {
      purchaseReceiptsInfos(this.input).then((data) => {
        if (data.code) {
          this.tableData = data.data.map((item, index) => {
            item.i = index + 1;
            return item;
          });
        } else {
          this.$message({
            type: "error",
            message: data.message,
          });
        }
      });
    },
    //是否含税
    employeeStatuse(i) {
      let val = "";
      if (i == 0) {
        val = "含税";
      }
      if (i == 1) {
        val = "不含税";
      }
      return val;
    },
    //性别显示
    employeeSex(i) {
      let val = "";
      if (i == 0) {
        val = "男";
      }
      if (i == 1) {
        val = "女";
      }
      return val;
    },
    //上传图片
    selectFile(i) {
      this.htdz = i;
      this.$refs.fileInput.click();
    },
    //上传oss
    handleFileChange(event) {
      this.selectedFile = event.target.files[0];
      if (this.htdz == 1) {
        this.imageUrl = URL.createObjectURL(this.selectedFile);
      }
      if (this.htdz == 2) {
        this.imageUrl2 = URL.createObjectURL(this.selectedFile);
      }
      this.uploadImage();
    },
    //初始化图片
    imgstatus() {
      let url =
        "https://kris-k.oss-cn-hangzhou.aliyuncs.com/kris/c179093a-41b0-4c70-bc1f-6e5973f35c98-jia.png";
      this.imageUrl = url;
      this.imageUrl2 = url;
    },
    //发送上传文件api
    uploadImage() {
      let formData = new FormData();
      formData.append("file", this.selectedFile);
      UploadFile(formData).then((data) => {
        let url = data.data;
        if (this.htdz == 1) {
          this.addEmployeeForm.employeeContractFile = url;
        }
        if (this.htdz == 2) {
          this.addEmployeeForm.employeeSecrecyFile = url;
        }
      });
    },

    //入库审核信息展示id
    InventoryDetails(id) {
      console.log("id", id);
      this.bt2 = false;
      purchaseReceiptsInfo(id).then((data) => {
        this.prudproducts = data.data;
        this.prudproducts.suppliersId = data.data.suppliersName;
        this.imageUrl = data.data.image;
      });
      this.addFromDialog = true;
    },
    //examineWarehousing 审核入库
    examineWarehousing(status) {
      adminCheck(this.prudproducts.receiptsId, status).then((data) => {
        if (data.code) {
          this.$message({
            type: "success",
            message: data.message,
          });
          this.getAllGoods();
        } else {
          this.$message({
            type: "error",
            message: data.message,
          });
        }
      });
    },
    //申请入库
    caigoAdd() {
      this.bt1 = true;
      this.bt2 = false;
      this.cgst = 0;
      this.addFromDialog4 = true;
      purchaseList().then((data) => {
        console.log("data", data.data);
        this.options3 = data.data;
      });
    },
    // 查询列表
    getAllGoods() {
      this.loading = true;
      const data = {
        receiptsStatus: this.receiptsStatusValue,
        currentPage: this.currentPage,
        pageSize: this.pageSize,
      }
      warehouseApi.getPurchaseReceiptsList(data).then(res => {
        if (res.code === 200) {
          this.loading = false;
          this.total = res.data.total;
          this.tableData = res.data.purchaseReceiptsVoList.map((item, index) => {
            item.i = (this.currentPage - 1) * this.pageSize + index + 1;
            return item;
          });
        }
      })
      //   purchaseReceiptsInfoList(
      //     this.currentPage,
      //     this.pageSize,
      //     this.receiptsStatusValue
      //   ).then((res) => {
      //     if (res.code == 200) {
      //       this.loading = false;
      //       this.total = res.data.total;
      //       this.tableData = res.data.purchaseInfoVoList.map((item,index) =>{
      //  item.i = (this.currentPage - 1) * this.pageSize + index + 1;
      //  return item;
      // });
      //       if (res.data.purchaseInfoVoList == null) {
      //         return;
      //       }
      //       //将图片地址放入数组,需要遍历循环加入数组
      //       for (let i = 0; i < res.data.purchaseInfoVoList.length; i++) {
      //         this.srcList.push(res.data.purchaseInfoVoList[i].image);
      //       }
      //       this.loading = false;
      //     } else {
      //       this.loading = false;
      //       this.$message("权限不足");
      //     }
      //     console.log("获取商品列表");
      //   });
    },
    // pageSize变化
    handleSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.getAllGoods();
    },
    // 页码变化
    handleCurrentChange(curPage) {
      this.currentPage = curPage;
      this.getAllGoods();
    },

    // getGoodsCategory() {
    //   getGoodsCategory().then((res) => {
    //     this.gooodsCategory = res.data.map((item) => ({
    //       label: item.name,
    //       value: item.id,
    //     }));
    //     console.log("获取商品类别", res);
    //   });
    // },
    // 删除商品
    deleteGoods(empl) {
      this.$confirm(
        `确定继续删除名为《${empl.employeeName}》的用户吗?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          deleteEmployeeProfileById(empl.id).then((res) => {
            if (res.code) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getAllGoods();
            } else {
              this.$message({
                type: "error",
                message: "删除失败!",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 查看零件列表
    partsOpen(row) {
      row.parts.forEach((part, index) => {
        part.i = index + 1
      })
      this.selectPurchase = row;
      this.selectTitle = row.suppliersName;
      this.partsShow = true;
    },
    // 关闭零件列表
    partsClose() {
      this.selectPurchase = {}
      this.selectTitle = ""
    },
    // 审核按钮类型
    applyType(receiptsStatus) {
      if (receiptsStatus === "0") {
        return "success";
      } else if (receiptsStatus === "1") {
        return "warning";
      }
      return "danger";
    },
    // 审核按钮禁用
    applyDisabled(receiptsStatus) {
      if (receiptsStatus === "1" &&
        (this.userInfo.roleId === "1" || this.userInfo.roleId === "5")) {
        return false;
      }
      return true;
    },
    // 审核按钮文字
    applyButtonText(receiptsStatus) {
      if (receiptsStatus === "0") {
        return "已通过"
      } else if (receiptsStatus === "1") {
        return "待审核"
      }
      return "不通过"
    },
    // 审核/详情按钮
    applyShow(row, index) {
      if (index === 0) {
        this.applyTitle = "入库审核"
        this.applyButton = true;
      } else {
        this.applyTitle = "详情"
        this.applyButton = false;
      }
      row.parts.forEach((part, index) => {
        part.i = index + 1
      })
      this.selectPurchase = row
      this.applyDialog = true;
    },
    // 入库审核
    applyOrders(index) {
      let msg = ""
      if (index === 0) {
        msg = "是否要通过入库申请"
      } else if (index === 2) {
        msg = "是否要驳回入库申请"
      }
      this.$confirm(msg, "提示", {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const data = {
          id: this.selectPurchase.id,
          receiptsStatus: index,
          supName: this.selectPurchase.suppliersName
        }
        warehouseApi.applyPurchaseReceipts(data).then(res => {
          if (res.code === 200) {
            this.$message.success("操作成功");
            this.selectPurchase = {}
            this.applyDialog = false;
            this.getAllGoods();
          }
        })
      })
    },
    // 重置
    reset() {
      this.receiptsStatusValue = null;
      this.getAllGoods();
    },
    // 删除
    deleteOrder(row) {
      this.$confirm("是否要删除该订单？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        warehouseApi.deletePurchaseReceipts(row).then(res => {
          if (res.code === 200) {
            this.$message.success("删除成功")
            this.getAllGoods();
          }
        }).finally(() => {
          loading.close();
        })
      }).catch(() => {

      });
    },
    // 查看零件行颜色
    tableRow({ row }) {
      //console.log("row==>", row)
      if (row.cost > row.purchasePrice) {
        return {
          background: '#cfffd7'
        };
      } else if (row.cost < row.purchasePrice) {
        return {
          background: '#ffe1e1'
        };
      }
      return {
        // background: 'oldlace'
        background: ''
      };
    },
  },
};
</script>

<style scoped>
.page {
  text-align: center;
}

.nameBox {
  overflow: auto;
  /* 显示滚动条 */
  z-index: 99;
  margin-top: 5px;
  font-size: 12px;
  text-align: center;
  width: 205px;
  height: 170px;
  border-radius: 5px;
  background-color: #ffffff;
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2);
  position: absolute;
}

.warehouse {
  height: 100%;
}

.goods-table {
  height: 94%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  margin-top: 10px;
}

.imgUrl {
  width: 100px;
  height: 100px;
  object-fit: cover;
  /* 保持原始宽高比，填充容器 */
}

.htimg {
  width: 150px;
  height: 150px;
  object-fit: cover;
  /* 保持原始宽高比，填充容器 */
}
</style>
